package com.project.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.project.service.ProjectManage;
import com.project.DAO.*;
import com.project.mapper.*;
import com.project.entity.*;

public class ProjectManageService implements ProjectManage {
	private ProjectManagementMapper projectManagementMapper;
	private ProjectManagementExample projectmanagementExample;
	private GeneralManagerMapper generalManagerMapper;
	private GeneralManagerExample generalManagerExample;
	private ProjectDistributeLogMapper projectDistributeLogMapper;
	private ProjectSuperVisoryManagementMapper projectSuperVisoryManagementMapper;
	private AlertEventMapper alertEventMapper;

	
	

	
	public AlertEventMapper getAlertEventMapper() {
		return alertEventMapper;
	}

	public void setAlertEventMapper(AlertEventMapper alertEventMapper) {
		this.alertEventMapper = alertEventMapper;
	}

	public ProjectSuperVisoryManagementMapper getProjectSuperVisoryManagementMapper() {
		return projectSuperVisoryManagementMapper;
	}

	public void setProjectSuperVisoryManagementMapper(
			ProjectSuperVisoryManagementMapper projectSuperVisoryManagementMapper) {
		this.projectSuperVisoryManagementMapper = projectSuperVisoryManagementMapper;
	}

	public ProjectDistributeLogMapper getProjectDistributeLogMapper() {
		return projectDistributeLogMapper;
	}

	public void setProjectDistributeLogMapper(
			ProjectDistributeLogMapper projectDistributeLogMapper) {
		this.projectDistributeLogMapper = projectDistributeLogMapper;
	}

	public GeneralManagerMapper getGeneralManagerMapper() {
		return generalManagerMapper;
	}

	public void setGeneralManagerMapper(GeneralManagerMapper generalManagerMapper) {
		this.generalManagerMapper = generalManagerMapper;
	}

	public GeneralManagerExample getGeneralManagerExample() {
		return generalManagerExample;
	}

	public void setGeneralManagerExample(GeneralManagerExample generalManagerExample) {
		this.generalManagerExample = generalManagerExample;
	}

	public ProjectManagementMapper getProjectManagementMapper() {
		return projectManagementMapper;
	}

	public void setProjectManagementMapper(
			ProjectManagementMapper projectManagementMapper) {
		this.projectManagementMapper = projectManagementMapper;
	}

	public ProjectManagementExample getProjectmanagementExample() {
		return projectmanagementExample;
	}

	public void setProjectmanagementExample(
			ProjectManagementExample projectmanagementExample) {
		this.projectmanagementExample = projectmanagementExample;
	}

	public int countAllProject() {
		ProjectManagementExample example = new ProjectManagementExample();
		return this.projectManagementMapper.countByExample(example);		
	}

	/**
	 * 获取所有的项目
	 */
	public List<ProjectManagement> getAllProject(Integer followup ,Integer start, Integer end){
//		System.out.println(start);
//		System.out.println(end);
		return projectManagementMapper.getAllProject(followup,start , end);
	}
	/**
	 * 获取所有符合条件的项目
	 */
	public List<ProjectManagement> getAllResultingProject(Map<String,Object> map){
		return this.projectManagementMapper.getAllResultingProject(map);
	}
	/**
	 * 获取符合条件的项目数
	 */
	public int countAllResultingProject(Map<String,Object> map){
		return this.projectManagementMapper.countAllResultingProject(map);
	}

	/**
	 * 插入项目记录
	 */
	public void insertProject(ProjectManagement projectManagement) {
		this.projectManagementMapper.insert(projectManagement);
	}
	/**
	 * 获取所有普通管理员
	 */
	public List<GeneralManager> getAllGeneralManager(Integer start, Integer end){
//		System.out.println(start);
//		System.out.println(end);
		return generalManagerMapper.getAllGeneralManager(start,end);
		
	}
	/**
	 * 获取普通管理员数量
	 */
	public int countAllGeneralManager() {
		GeneralManagerExample example = new GeneralManagerExample();
		return this.generalManagerMapper.countByExample(example);		
	}
	/**
	 * 修改项目跟进人
	 * 
	 */
	public void changeFollowUpPerson(ProjectManagement projectManagement,ProjectManagementExample example){
		this.projectManagementMapper.updateByExampleSelective(projectManagement, example);
		return;
	}
	/**
	 * 修改监督管理跟进人
	 */
	public void changeSupervisoryFollowUpPerson(ProjectSuperVisoryManagement projectSuperVisoryManagement,ProjectSuperVisoryManagementExample example){
		this.projectSuperVisoryManagementMapper.updateByExampleSelective(projectSuperVisoryManagement, example);
		return;
	}
	/**
	 * 插入项目分发日志
	 */
	public void insertProjectDistributeLog(ProjectDistributeLog projectDistributeLog){
//		System.out.println(projectDistributeLog.getProjectnumber());
//		System.out.println(projectDistributeLog.getProjectreceiver());
//		System.out.println(projectDistributeLog.getProjectdistributer());
		this.projectDistributeLogMapper.insertSelective(projectDistributeLog);
		return;
	}
	/**
	 * 获取所有符合条件的项目监督信息
	 */
	public List<ProjectSuperVisoryManagement> getAllResultingProjectSupervise(Map<String,Object>map){
		return this.projectSuperVisoryManagementMapper.getAllResultingProjectSupervise(map);
	}
	/**
	 * 获取符合条件的项目监督信息数目
	 */
	public int countAllResultingProjectSupervise(Map<String,Object> map){
		return this.projectSuperVisoryManagementMapper.countAllResultingProjectSupervise(map);
	}
	/**
	 * 修改项目监督情况
	 */
	public void changeProjectSupervise(ProjectSuperVisoryManagement projectSuperVisoryManagement,ProjectSuperVisoryManagementExample example){
		System.out.println("ohck");
		System.out.println(projectSuperVisoryManagement.getProjectnumber());
		System.out.println(projectSuperVisoryManagement.getProjectfollowupsituation());
		System.out.println(projectSuperVisoryManagement.getProjectstate());
		this.projectSuperVisoryManagementMapper.updateByExampleSelective(projectSuperVisoryManagement, example);
		return;
	}
	

	/**
	 * 获取所有符合条件的发布事件提醒数目
	 */
	public int countAllResultingAlertEventPub(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return alertEventMapper.countAllResultingAlertEventPub(map);
	
	}

	/**
	 * 获取所有符合条件的接收事件提醒数目
	 */
	public int countAllResultingAlertEventRec(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.alertEventMapper.countAllResultingAlertEventRec(map);
	}

	/**
	 * 获取所有符合条件的发布事件提醒
	 */
	public List<AlertEvent> getAllResultingAlertEventPub(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.alertEventMapper.getAllResultingAlertEventPub(map);
	}

	/**
	 * 获取所有符合条件的接收事件提醒
	 */
	public List<AlertEvent> getAllResultingAlertEventRec(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return this.alertEventMapper.getAllResultingAlertEventRec(map);
	}
	/**
	 * 更新提醒事件状态
	 */
	public void updateAlertEventState(AlertEvent event,AlertEventExample example){
		this.alertEventMapper.updateByExampleSelective(event, example);
		return;
	}
	/**
	 * 删除接收的提醒事件
	 */
	public void delAlertEventRec(Map<String,Object>map){
		this.alertEventMapper.delAlertEventRec1(map);
		this.alertEventMapper.delAlertEventRec2(map);
	}
	/**
	 * 删除发送的提醒事件
	 */
	public void delAlertEventPub(Map<String,Object>map){
		this.alertEventMapper.delAlertEventPub1(map);
		this.alertEventMapper.delAlertEventPub2(map);
	}
	/**
	 * 发布提醒事件
	 */
	public void publishAlertEvent(AlertEvent event){
		this.alertEventMapper.insert(event);
	}

	/**
	 * 动态条件查询
	 */
	public List<ProjectManagement> multiConditionQuery(String type,
			String keyWord, String beginYear, String endYear) {
		ProjectManagementExample example = new ProjectManagementExample();
		System.out.print(keyWord);
		if (!type.equals("") && type != null && !keyWord.equals("")
				&& keyWord != null)// 判断若查询条件且关键字都不为空，则嵌入该查询条件
		{
			if (type.equals("projectid")) {
				example.createCriteria().andProjectidEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("projectnumber")) {
				example.createCriteria().andProjectnumberEqualTo(keyWord);
			}

			if (type.equals("projectname")) {
				example.createCriteria().andProjectnameEqualTo(keyWord);
			}

			if (type.equals("location")) {
				example.createCriteria().andLocationEqualTo(keyWord);
			}

			if (type.equals("mainundertakeunit")) {
				example.createCriteria().andMainundertakeunitEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("guaranteeunit")) {
				example.createCriteria().andGuaranteeunitEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("unitedunitone")) {
				example.createCriteria().andUnitedunitoneEqualTo(keyWord);
			}

			if (type.equals("unitedunitone")) {
				example.createCriteria().andUnitedunitoneEqualTo(keyWord);
			}

			if (type.equals("unitedunittwo")) {
				example.createCriteria().andUnitedunittwoEqualTo(keyWord);
			}

			if (type.equals("unitedunitthree")) {
				example.createCriteria().andUnitedunitthreeEqualTo(keyWord);
			}

			if (type.equals("unitedunitfour")) {
				example.createCriteria().andUnitedunitfourEqualTo(keyWord);
			}

			if (type.equals("establishprojectyear")) {
				example.createCriteria()
						.andEstablishprojectyearEqualTo(keyWord);
			}

			if (type.equals("mainmanagingdepartment")) {
				example.createCriteria().andMainmanagingdepartmentEqualTo(
						keyWord);
			}

			if (type.equals("followupperson")) {
				example.createCriteria().andFollowuppersonEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("projectplancatagory")) {
				example.createCriteria().andProjectplancatagoryEqualTo(keyWord);
			}

			if (type.equals("field")) {
				example.createCriteria().andFieldEqualTo(keyWord);
			}

			if (type.equals("subfield")) {
				example.createCriteria().andSubfieldEqualTo(keyWord);
			}

			if (type.equals("issuefilenumber")) {
				example.createCriteria().andIssuefilenumberEqualTo(keyWord);
			}

			if (type.equals("winbidmoney")) {
				example.createCriteria().andWinbidmoneyEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("projectdirector")) {
				example.createCriteria().andProjectdirectorEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("officephone")) {
				example.createCriteria().andOfficephoneEqualTo(keyWord);
			}

			if (type.equals("mobilephone")) {
				example.createCriteria().andMobilephoneEqualTo(keyWord);
			}

			if (type.equals("directoremail")) {
				example.createCriteria().andDirectoremailEqualTo(keyWord);
			}

			if (type.equals("contactman")) {
				example.createCriteria().andContactmanemailEqualTo(keyWord);
			}

			if (type.equals("phoneone")) {
				example.createCriteria().andPhoneoneEqualTo(keyWord);
			}

			if (type.equals("phonetwo")) {
				example.createCriteria().andPhonetwoEqualTo(keyWord);
			}

			if (type.equals("contactmanemail")) {
				example.createCriteria().andContactmanemailEqualTo(keyWord);
			}

			/*
			 * if(type.equals("checkdate")){
			 * example.createCriteria().andCheckdateEqualTo(null); }
			 */

			if (type.equals("projectschedule")) {
				example.createCriteria().andProjectscheduleEqualTo(keyWord);
			}

			if (type.equals("projectchange")) {
				example.createCriteria().andProjectchangeEqualTo(keyWord);
			}

			if (type.equals("inventpatentapplication")) {
				example.createCriteria().andInventpatentapplicationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("inventpatentauthorization")) {
				example.createCriteria().andInventpatentauthorizationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("usenewapplication")) {
				example.createCriteria().andUsenewapplicationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("usenewauthorization")) {
				example.createCriteria().andUsenewauthorizationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("appearancedesignapplication")) {
				example.createCriteria().andAppearancedesignapplicationEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("appearancedesignauthorization")) {
				example.createCriteria()
						.andAppearancedesignauthorizationEqualTo(
								Integer.valueOf(keyWord));
			}

			if (type.equals("foreignpatent")) {
				example.createCriteria().andForeignpatentEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newtechnology")) {
				example.createCriteria().andNewtechnologyEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newproduct")) {
				example.createCriteria().andNewproductEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newmaterial")) {
				example.createCriteria().andNewmaterialEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("newequipment")) {
				example.createCriteria().andNewequipmentEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("computersoftware")) {
				example.createCriteria().andComputersoftwareEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("paper")) {
				example.createCriteria().andPaperEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("technologystandard")) {
				example.createCriteria().andTechnologystandardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("nationalaward")) {
				example.createCriteria().andNationalawardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("provincialaward")) {
				example.createCriteria().andProvincialawardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("cityaward")) {
				example.createCriteria().andCityawardEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("doctor")) {
				example.createCriteria().andDoctorEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("master")) {
				example.createCriteria().andMasterEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("undergraduate")) {
				example.createCriteria().andUndergraduateEqualTo(
						Integer.valueOf(keyWord));
			}

			if (type.equals("fundsavailable")) {
				example.createCriteria().andFundsavailableEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("fundsinvestment")) {
				example.createCriteria().andFundsinvestmentEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("benefitacquired")) {
				example.createCriteria().andBenefitacquiredEqualTo(
						Float.valueOf(keyWord));
			}

			if (type.equals("projectsummary")) {
				example.createCriteria().andProjectsummaryEqualTo(keyWord);
			}
		}

		List<ProjectManagement> rs = new ArrayList();
		List<ProjectManagement> tmp = this.projectManagementMapper
				.selectByExample(example);
		if (beginYear != null && (!beginYear.equals(""))) {
			if (endYear != null && (!endYear.equals(""))) {
				for (ProjectManagement pro : tmp) {
					if (Integer.parseInt(pro.getEstablishprojectyear()
							.toString()) <= Integer.parseInt(endYear)
							&& Integer.parseInt(pro.getEstablishprojectyear()
									.toString()) >= Integer.parseInt(beginYear)) {
						rs.add(pro);
					}
				}// 以立项时间为查询条件之一
			} else {
				for (ProjectManagement pro : tmp) {
					if (Integer.parseInt(pro.getEstablishprojectyear()
							.toString()) >= Integer.parseInt(beginYear)) {
						rs.add(pro);
					}
				}
			}
		} else if (endYear != null && (!endYear.equals(""))) {
			for (ProjectManagement pro : tmp) {
				if (Integer.parseInt(pro.getEstablishprojectyear().toString()) <= Integer
						.parseInt(endYear)) {
					rs.add(pro);
				}

			}
		}
		return tmp;
	}

}
